﻿/// <reference path="fourkill.util.js" />
/// <reference path="post.fourkill.sprite.singletons.js" />
/// <reference path="../views/fourkill.view.login.js" />
/// <reference path="../views/fourkill.view.fourkill3d.js" />
/// <reference path="../input/init.fourkill.input.base.js" />
/// <reference path="../input/fourkill.input.gps.js" />
/// <reference path="../input/post.fourkill.input.singletons.js" />

var game = null;

$(window).resize(function () {
    if (game != null && game.getView().isActive) {
        game.resize();
    }
});


$(document).ready(function () {
    var fishers = util.toECEF(39.955943, -86.013181);
    var paris = util.toECEF(48.8534100, 2.3488000);
    var london = util.toECEF(51.5085300, -0.1257400);
    var honalulu = util.toECEF(21.3069400, -157.8583300);
    var capetown = util.toECEF(-33.9166700, 18.4166700);

    var left = util.toECEF(179.99, 0);
    var right = util.toECEF(-179.99, 0);

    /*alert(
        "fishers (" + fishers.x + ", " + fishers.y + ") (-86.013181, 39.955943)\r\n" +
        "fishersJ (" + fishersJ.x + ", " + fishersJ.y + ") (-86.013181, 39.955943)\r\n" +
        "paris (" + paris.x + ", " + paris.y + ")\r\n" +
        "parisJ (" + parisJ.x + ", " + parisJ.y + ")\r\n" +
        "london (" + london.x + ", " + london.y + ")\r\n" +
        "londonJ (" + londonJ.x + ", " + londonJ.y + ")\r\n" +
        "honalulu (" + honalulu.x + ", " + honalulu.y + ")\r\n" +
        "honaluluJ (" + honaluluJ.x + ", " + honaluluJ.y + ")\r\n" +
        "capetown (" + capetown.x + ", " + capetown.y + ")\r\n" +
        "capetownJ (" + capetownJ.x + ", " + capetownJ.y + ")");*/
    $.mobile.initializePage();
});

$(document).bind("pageinit", function () {
    $(".ui-loader").hide();
    game = Game.newInstance();
    game.currentView = "gps_testing";
    game.getView().setup();
});

var Player = Base.extend({
    initialize: function initialize() {
        this.name = "Anonymous",
        this.oid = 0
    }
});

var Game = Base.extend({
    initialize: function initialize() {
        this.views = {
            //"fourkill_map" : FourKillGameViewMap.newInstance(this),
            "gps_testing": GpsTestsView.newInstance(this),
        };
        this.player = Player.newInstance();
        this.currentView = "fourkill_minimal";
    },
    getView: function getView(viewName) {
        viewName = viewName == null ? this.currentView : viewName;
        return this.views[viewName];
    },
    changeView: function changeView(viewName) {
        this.getView().teardown();
        this.currentView = viewName;
        if (this.getView().isActive) this.getView().resume();
        else this.getView().setup();
    },
    setup: function setup() {
        this.views[this.currentView].setup();
    },
    teardown: function teardown() {
        this.views[this.currentView].teardown();
    },
    resize: function resize() {
        for (viewId in this.views) this.views[viewId].resize();
    },
    notify: function notify(msgType, msgContent) {
        if (msgType == "login") {
            this.changeView(msgContent.targetView);
        }
        if (msgType == "change-view") {
            this.changeView(msgContent);
        }
    }
});
